package com.taskcollection.util;


import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * Created by Administrator on 2016/7/30 0030.
 */
public class MybatisUtil {
    private static MybatisUtil mybatis;
    private SqlSessionFactory factory;
    private MybatisUtil() {
        try {
            Reader inputStream = Resources.getResourceAsReader("mybatis.xml");
            factory = new SqlSessionFactoryBuilder().build(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static MybatisUtil getinstance(){
        if(mybatis==null){
            mybatis=new MybatisUtil();
        }
        return mybatis;
    }
    public SqlSessionFactory getFactory(){
        return this.factory;
    }
}
